Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kew

Package Overview
Dependencies
Maintainers
6
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kew

a lightweight promise library for node

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is kew?

The 'kew' npm package is a lightweight promise library for Node.js that provides a simple and efficient way to handle asynchronous operations. It is designed to be fast and easy to use, offering a minimalistic API for creating and managing promises.

What are kew's main functionalities?

Creating Promises

This feature allows you to create promises using the 'kew' library. The example demonstrates how to create a deferred object, resolve it after a timeout, and handle the resolved value using the 'then' method.

const Q = require('kew');

function asyncTask() {
  const defer = Q.defer();
  setTimeout(() => {
    defer.resolve('Task completed');
  }, 1000);
  return defer.promise;
}

asyncTask().then(result => {
  console.log(result); // 'Task completed'
});

Chaining Promises

This feature allows you to chain multiple promises together. The example demonstrates how to chain two asynchronous tasks, where the second task starts only after the first task is completed.

const Q = require('kew');

function firstTask() {
  const defer = Q.defer();
  setTimeout(() => {
    defer.resolve('First task completed');
  }, 1000);
  return defer.promise;
}

function secondTask() {
  const defer = Q.defer();
  setTimeout(() => {
    defer.resolve('Second task completed');
  }, 1000);
  return defer.promise;
}

firstTask()
  .then(result => {
    console.log(result); // 'First task completed'
    return secondTask();
  })
  .then(result => {
    console.log(result); // 'Second task completed'
  });

Handling Errors

This feature allows you to handle errors in asynchronous operations. The example demonstrates how to create a promise that rejects with an error and how to handle the error using the 'fail' method.

const Q = require('kew');

function asyncTaskWithError() {
  const defer = Q.defer();
  setTimeout(() => {
    defer.reject(new Error('Something went wrong'));
  }, 1000);
  return defer.promise;
}

asyncTaskWithError()
  .then(result => {
    console.log(result);
  })
  .fail(error => {
    console.error(error.message); // 'Something went wrong'
  });

Other packages similar to kew

Keywords

FAQs

Package last updated on 24 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc